package nbpMaven2.nbpMaven2;

import static org.junit.Assert.assertEquals;

import java.math.BigDecimal;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import org.junit.Test;

public class JUnitCurrTest {

	/********************** JUNIT TEST (02.10.2014) ****************************/

	@Test
	public void testSetCurrencyToCountry() {
		// given
		CurrencyPostgres cp = new CurrencyPostgres();
		String currCode = "EUR";
		String currName = "Chorwacja";

		// when
		cp.setCurrencyToCountry(currCode, currName);

		// then
	}

	@Test
	public void testGetMaxCurrValue() {
		// given
		CurrencyPostgres cp = new CurrencyPostgres();
		Date date = new Date();
		String currCode = "INR";
		BigDecimal currVal = BigDecimal.valueOf(5.2777);

		// when
		CurrencyInfoClass cic = cp.getMaxCurrValue(date);

		// then
		assertEquals(currCode, cic.getShortcut());
		assertEquals(currVal, cic.getBd());
	}

	@Test
	public void testGetMinCurrValue() {
		// given
		Date date = new Date();
		CurrencyPostgres cp = new CurrencyPostgres();
		String currCode = "PHP";
		BigDecimal currVal = BigDecimal.valueOf(0.0732);

		// when
		CurrencyInfoClass cic = cp.getMinCurrValue(new Date());

		// then
		assertEquals(currCode, cic.getShortcut());
		assertEquals(currVal, cic.getBd());
	}

	@Test
	public void testSearchForMoreCurrency() {
		// given
		CurrencyPostgres cp = new CurrencyPostgres();
		Date date = new Date();
		String country = "poland";

		// when
		List<CurrencyInfoClass> returnedList = cp.searchForMoreCurrency();

		// then
		assertEquals(country, returnedList.get(0).getShortcut());

	}

	@Test
	public void testGetMinMaxCurrValue() {
		// given
		Calendar cal = Calendar.getInstance();
		cal.set(Calendar.YEAR, 2014);
		cal.set(Calendar.MONTH, 6);
		cal.set(Calendar.DAY_OF_MONTH, 23);
		Date date = cal.getTime();
		Calendar cal2 = Calendar.getInstance();
		cal2.set(Calendar.YEAR, 2014);
		cal2.set(Calendar.MONTH, 6);
		cal2.set(Calendar.DAY_OF_MONTH, 27);
		Date date2 = cal2.getTime();
		CurrencyPostgres cp = new CurrencyPostgres();
		String maxCurrShortcut = "GBP";
		String minCurrShortcut = "PHP";
		BigDecimal maxCurrVal = BigDecimal.valueOf(5.2134);
		BigDecimal minCurrVal = BigDecimal.valueOf(0.0697);

		// when
		List<CurrencyInfoClass> returnedList = cp.getMinMaxCurrValue(date, date2);

		// then
		assertEquals(maxCurrShortcut, returnedList.get(0).getShortcut());
		assertEquals(maxCurrVal, returnedList.get(0).getBd());
		assertEquals(minCurrShortcut, returnedList.get(1).getShortcut());
		assertEquals(minCurrVal, returnedList.get(1).getBd());
	}

	@Test
	public void testGetBiggestDifference() {
		// given
		Calendar cal = Calendar.getInstance();
		cal.set(Calendar.YEAR, 2014);
		cal.set(Calendar.MONTH, 6);
		cal.set(Calendar.DAY_OF_MONTH, 23);
		Date date = cal.getTime();
		Calendar cal2 = Calendar.getInstance();
		cal2.set(Calendar.YEAR, 2014);
		cal2.set(Calendar.MONTH, 6);
		cal2.set(Calendar.DAY_OF_MONTH, 27);
		Date date2 = cal2.getTime();
		CurrencyPostgres cp = new CurrencyPostgres();
		String givenCurrency = "funt szterling";

		// when
		String returnedCurrency = cp.getBiggestDifference(date, date2);

		// then
		assertEquals(givenCurrency, returnedCurrency);
	}

}
